#include <iostream>
#include <cstdlib>
#include <algorithm>
#define MAX_BOX 30
#define MAX_DIMENSION 10

using namespace std;

struct Box {
	int no;
	int edge[MAX_DIMENSION];
	int dimension;
	bool operator < (const Box&) const;
};

bool Box::operator < (const Box& other) const {
	for(int i = 0; i < dimension; ++i)
		if( !(edge[i] < other.edge[i]) )
			return false;
	return true;
}

bool box_less(const Box&, const Box&);

int main(void) {
	Box box[30];
	int num_box, dimension;
	int length[MAX_BOX];
	int prev[MAX_BOX];

	while (cin >> num_box >> dimension) {
		for (int i = 0; i < num_box; ++i) {
			box[i].no = i + 1;
			box[i].dimension = dimension;
			for (int j = 0; j < dimension; ++j)
				cin >> box[i].edge[j];
			//sort edge in the box
			sort(box[i].edge, box[i].edge + dimension);
			//every box at least have itself's box length
			length[i] = 1;
			//-1 rerpesents not include box
			prev[i] = -1;
		}

		//box sort
		sort(box, box + num_box, box_less);

		//find the length of all boxes
		for (int i = 0; i < num_box; ++i) {
			for (int j = i + 1; j < num_box; ++j) {
				if (box[i] < box[j]) {
					if (length[i] + 1 > length[j]) {
						length[j] = length[i] + 1;
						//prev[j] represents the j-th box including which box at the index value
						prev[j] = i;
					}
				}
			}
		}

		//find the max length of all boxes
		int max = max_element(length, length + num_box) - length;

		//print the result
		cout << length[max] << endl;

		int output_seq[MAX_BOX];
		int size = 0;

		int cur = max;
		do {
			output_seq[size++] = box[cur].no;
			cur = prev[cur];
		} while (cur != -1);

		for (int i = size - 1; i > 0; --i)
			cout << output_seq[i] << " ";
		cout << output_seq[0] << endl;
	}

#ifndef ONLINE_JUDGE
	system("pause");
#endif

	return 0;
}

bool box_less(const Box& a, const Box& b) {
	for(int i = 0; i < a.dimension; ++i)
		if( !(a.edge[i] <= b.edge[i]) )
			return false;
	return true;
}
